package com.tuling.jucdemo.sync;

import lombok.extern.slf4j.Slf4j;

/**
 * @author :tangweiliang
 * @date : 2022/11/9 22:28
 * 未来的你会感谢现在努力的你
 *
 * 根据QMode的不同，会执行不同的唤醒策略
 */
@Slf4j
public class SyncQModeDemo {

    public static void main(String[] args) throws InterruptedException {
        SyncQModeDemo demo = new SyncQModeDemo();
        demo.threadA();
        Thread.sleep(100);
        demo.threadB();
        Thread.sleep(100);
        demo.threadC();

    }

    private static java.lang.Object lock = new Object();
    public void threadA(){
        new Thread(()->{
            synchronized (lock){
                try {
                    log.debug("A get lock");
                   Thread.sleep(300);
                    //lock.wait(300);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("A release lock");
            }
        },"thread-A").start();
    }

    public void threadB(){
        new Thread(()->{
           synchronized (lock){
               try {
                   log.debug("B get lock");
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               log.debug("B release lock");
           }
        },"thread-B").start();
    }

    public void threadC(){
        new Thread(()->{
            synchronized (lock){
                log.debug("C get lock");
            }
        },"thread-C").start();
    }
}
